package com.shitou.web;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.shitou.pojo.Issues;
import com.shitou.pojo.Milestone;
import com.shitou.pojo.Project;
import com.shitou.pojo.User;
import com.shitou.service.AssignmentService;
import com.shitou.service.IssuesService;
import com.shitou.service.MilestoneService;
import com.shitou.service.ProjectService;
import com.shitou.util.AssignmentUtil;

@Results({@Result(name=BaseAction.RELOAD, params={"id","${id}"}, location="issues.jspx", type="redirectAction" )})
public class IssuesAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	@Resource
	private ProjectService projectService;
	private Project project;
	private int projectid;
	private List<Milestone> milestoneList;
	@Resource
	private IssuesService issuesService;
	private Issues issues;
	private Integer id;
	@Resource
	private MilestoneService milestoneService;
	private Milestone milestone;
	private int type;
	@Resource
	private AssignmentService assignmentService;

	@Override
	public String del() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String input() throws Exception {
		project = projectService.findById(projectid);
		milestoneList = project.getMilestones();
		return INPUT;
	}

	@Override
	public String list() throws Exception {
		issues = issuesService.findById(id);
		return SUCCESS;
	}

	@Override
	public String save() throws Exception {
		User user = (User) getSessionAttribute("user");
		if(milestone.getId() != 0) {
			milestone = milestoneService.findById(milestone.getId());
			id = issuesService.save(issues, milestone, user);
		} else {
			project = projectService.findById(projectid);
			id = issuesService.save(issues, project, user);
		}
		return RELOAD;
	}

	//getter and setter
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public Issues getIssues() {
		return issues;
	}

	public void setIssues(Issues issues) {
		this.issues = issues;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getProjectid() {
		return projectid;
	}

	public void setProjectid(int projectid) {
		this.projectid = projectid;
	}

	public List<Milestone> getMilestoneList() {
		return milestoneList;
	}

	public void setMilestoneList(List<Milestone> milestoneList) {
		this.milestoneList = milestoneList;
	}

	public Milestone getMilestone() {
		return milestone;
	}

	public void setMilestone(Milestone milestone) {
		this.milestone = milestone;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
}
